<template>
    <div class="flex justify-between flex-wrap mb-2">
      <el-space wrap :size="10" class="">
        <el-input
          v-model="params.user_name"
          style="width: 150px"
          placeholder="用户名称"
        />
        <el-checkbox v-model="params.is_balance" label="有余额用户" />
        <el-button :icon="Search" plain @click="search">查詢</el-button>
      </el-space>
      <el-space wrap :size="10">
        <el-button type="primary" plain>减少</el-button>
        <el-button type="primary" plain>增加</el-button>
        <el-button type="primary" plain>清零</el-button>
        <el-button type="primary" plain>导入购物车</el-button>
        <el-dropdown type="primary">
          <el-button type="primary">
            下載<el-icon class="el-icon--right"><arrow-down /></el-icon>
          </el-button>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>下載列表</el-dropdown-item>
              <el-dropdown-item>购物车导入模版下载</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </el-space>
    </div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="user_id" label="ID" />
      <el-table-column prop="user_name" label="用户名称" />
      <el-table-column prop="gold_plus" label="购物金(+)" />
      <el-table-column prop="gold_minus" label="购物金(-)" />
      <el-table-column prop="balance" label="余额" />
    </el-table>
    <div v-if="total > params.page_size" class="mt-2 flex justify-center">
      <el-pagination
        v-model:current-page="params.current_page"
        v-model:page-size="params.page_size"
        :page-sizes="[10, 20, 30, 40]"
        :small="false"
        :disabled="false"
        :background="true"
        layout="total, sizes, prev, pager, next"
        :total="Number(total)"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
</template>
<script lang="ts" setup>
import { ref, onMounted } from "vue";
import { Search, PriceTag,ArrowDown } from "@element-plus/icons-vue";
import { $getGold } from "@api/market";
let params = ref({
  current_page: 1,
  page_size: 10,
  is_balance:false,
  user_name: "",
});
const total = ref(0);
const tableData = ref([]);
onMounted(() => {
  getData();
});
const getData = async () => {
  let res = await $getGold(params.value);
  if (res.code == 0) {
    tableData.value = res.data.table;
    total.value = res.data.total;
  }
};
const handleSizeChange = (val: number) => {
  params.value.page_size = val;
  getData();
};
const handleCurrentChange = (val: number) => {
  params.value.current_page = val;
  getData();
  console.log(`current page: ${val}`);
};
const handleSelectionChange = (val: array) => {
  console.log(val);
  multipleSelection.value = val;
};
const search = () => {
  console.log(params.value);
  getData();
};
const handleEdit = (index: number, row: any) => {
  console.log(val);
};
</script>

<style lang="scss" scoped></style>
@/api/live
